package app.web.admin.domain.pojo;

import app.core.ar.Ar;
import com.gitee.feizns.quickstart.ddl.annotation.Comment;
import com.gitee.feizns.quickstart.domain.Types;
import com.gitee.feizns.quickstart.domain.query.Relationship;
import com.mybatisflex.core.handler.JacksonTypeHandler;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.List;

/**
 * 角色
 * @author feizns
 * @since 2025/3/11
 */
@Data
@Entity
@Comment("角色")
@EqualsAndHashCode(callSuper = true)
@Table(name = "admin_role")
@com.mybatisflex.annotation.Table(value = "admin_role", comment = "角色")
public class AdminRole extends Ar<AdminRole> {

    /**
     * 超管理编号
     */
    public static final Long SuperAdminRoleId = 1L;

    /**
     * 角色名称
     */
    @Comment("角色名称")
    private String name;

    /**
     * 角色组名称
     */
    @Comment("角色组名称")
    private String groupName;

    /**
     * 菜单编号列表
     */
    @Comment("菜单编号列表")
    @Type(type = Types.JSON)
    @Column(columnDefinition = Types.JSON)
    @com.mybatisflex.annotation.Column(typeHandler = JacksonTypeHandler.class)
    private List<Long> menuIds;

    /**
     * 具有角色权限
     * @return {@link Relationship }<{@link AdminRoleOfMenu }, {@link Long }, {@link Long }>
     */
    public Relationship<AdminRoleOfMenu, Long, Long> relationshipOfRoleMenus() {
        return Relationship.of(AdminRoleOfMenu::getRoleId, this.getId(), AdminRoleOfMenu::getMenuId);
    }

}
